function showSuperviseVehicleSearch() {
	window.location.href = "showSuperviseVehicleSearch.do";
}

function ajaxFindSuperviseVehicleSearchList(currentPage,pageSize) {
	$.ajax({
		type : "post",
		url : "ajaxSuperviseVehicleSearchList.do",
		data : {
			plateNum : $("#plateNum").val(),
			plateTypeId : $("#licencePlateKind").val(),
			vehicleTypeId : $("#vehicleType").val(),
		    ownername : $("#ownername").val(),
			effectiveStartTime : $("#effectiveStartTime").val(),
			effectiveEndTime : $("#effectiveEndTime").val(),
			currentPage:currentPage,
			pageSize:pageSize,
		},
		success : function(msg) {
			$("#listSuperviseVehicleBox").html(msg);
		}
	});
}

function ajaxShowSuperviseVehicleEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowSuperviseVehicleEdit.do",
		data:{superviseVehicleId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 740,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveSuperviseVehicle(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}

function ajaxSaveSuperviseVehicle(objDialog) {
	superviseVehicleValidate();
	if ($("#frmSuperviseVehicle").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveSuperviseVehicle.do",
				success: function (msg) {
					clearInput("#sltSuperviseVehicle");
					showMessageDialog("保存布控车辆信息","布控车辆信息保存成功。",null,dialogType.info);
					ajaxFindSuperviseVehicleSearchList();
				}
		};
		$("#frmSuperviseVehicle").ajaxSubmit(options);
	}
}

function ajaxShowSuperviseVehicleView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowSuperviseVehicleView.do",
		data:{superviseVehicleId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 740,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxDeleteSuperviseVehicleById(id) {
	var superviseVehicleIds="";
	var sltSC = $("#listSuperviseVehicleList tbody input:checked").length;
	if(id==null){
		$("#listSuperviseVehicleList tbody input:checked").each(function(){ 
			superviseVehicleIds += $(this).val()+";";
		});
		if(sltSC == 0){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			superviseVehicleIds = superviseVehicleIds.substring(0, superviseVehicleIds.length-1);
		} 
	}else{
		superviseVehicleIds=id;
		sltSC = 1;
	}
	if( superviseVehicleIds!=null){
		showMessageDialog("删除布控车辆信息","确定要删除所选“"+sltSC+"”条布控车辆信息记录吗？",
				function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeleteSuperviseVehicleByIds.do",
				data:{superviseVehicleIds:superviseVehicleIds},
				success:function(msg){
					ajaxFindSuperviseVehicleSearchList();
					showMessageDialog("提示","布控车辆信息删除成功",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}

function superviseVehicleValidate(){
	$("#frmSuperviseVehicle").validate({
		errorLabelContainer: $("#infoSuperviseVehicle"),
		rules : {
			plateNum : {
				required :true				
			},
			plateTypeId : {
				required :true				
			},
			superviseTypeId : {
				required :true				
			},
			vehicleSource : {
				required :true				
			}
		},
		messages : {
			plateNum : {
				required :"请输入号牌号码！"
			},
			plateTypeId : {
				required :"请选择号牌种类！"
			},
			superviseTypeId : {
				required :"请选择布控类型！"
			},
			vehicleSource : {
				required :"请输入车辆来源！"
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}
